import java.util.Scanner;

public class InverseNumberCalculator {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // 读取用户输入
        System.out.println("请输入数字，用空格分隔：");
        String input = scanner.nextLine().trim();

        // 分割输入字符串并转换为整数数组
        String[] numbers = input.split("\\s+");
        int[] array = new int[numbers.length];

        try {
            for (int i = 0; i < numbers.length; i++) {
                array[i] = Integer.parseInt(numbers[i]);
            }
        } catch (NumberFormatException e) {
            System.out.println("错误：输入包含非数字内容！");
            return;
        }

        // 计算逆序数
        int inversionCount = countInversions(array);

        // 输出结果
        System.out.println("逆序数为：" + inversionCount);
    }

    // 使用双重循环计算逆序数
    private static int countInversions(int[] array) {
        int count = 0;
        for (int i = 0; i < array.length - 1; i++) {
            for (int j = i + 1; j < array.length; j++) {
                if (array[i] > array[j]) {
                    count++;
                }
            }
        }
        return count;
    }
}